import path from 'path';
import { createRequire } from 'module';
import { pathToFileURL } from 'url';

const require = createRequire(import.meta.url);

/**
 * @description 根目录（ESM 兼容写法）
 */
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const ROOT_PATH = process.cwd();

// 使用 require 读取 package.json（更简单可靠）
const pkg = require(path.join(ROOT_PATH, 'package.json'));
const { version = '1.0.0', author = '明空' } = pkg;
/**
 * @description 程序目录
 */
const APP_PATH = path.join(ROOT_PATH, 'app');

const baseConfig = {
  JSON_LIMIT: "100kb",
  logger: {
    level: 'dev',
  },
  version,
  author,
  env: 'dev',
  template: 'default',
  views: [],
  static: [{
    prefix: "/public/",
    dir: ["app/public"],
    maxAge: 0,
  }],
  database: {
    client: "mysql2",
    host: "localhost",
    port: "3306",
    user: "root",
    password: "123456",
    database: "chancms",
    charset: "utf8mb4",
  }
};

// 导出配置对象
export default {
  ROOT_PATH,
  APP_PATH,
  ...baseConfig
};